const http = require("http");
const fs = require("fs");
const path = require("path");
const jsdom = require("jsdom");
const { JSDOM } = jsdom;
import fetch from "node-fetch"

console.log(typeof fetch);

let server = http.createServer((req , res) => {
    console.log(req.url);
    if(req.url === '/') {
        let content = fs.readFileSync("./index.html");
        // console.log(content);
        let dom = new JSDOM(content.toString());
        let folder = dom.window.document.querySelector(".folder");
        fetch("./data.json").then(res => res.json()).then(data => {console.log(data)});
        console.log(folder);
        res.end(content);
    } else if(req.url.indexOf("/image") >= 0) {
        let data = fs.readFileSync(path.join(__dirname , req.url));
        res.end(data);
    }
}).listen(3000);